package n1837;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	static int dp[][]=new int[21][15000];
	
	static int C,G;
	static int hook[]=new int[20];
	static int weight[]=new int[20];
	
	
	static int solve()
	{
		dp[0][7499]=1;
		
		for(int i=1;i<G+1;i++)
		{
			for(int j=0;j<15000;j++)
			{
				if(dp[i-1][j]!=0)
				{
					for(int k=0;k<C;k++)
					{
						dp[i][j+hook[k]*weight[i-1]]+=dp[i-1][j];
					}
				}
			}
		}
		
		return dp[G][7499];
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{

		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(bf.readLine());
		
		C=Integer.parseInt(st.nextToken());
		G=Integer.parseInt(st.nextToken());
		st=new StringTokenizer(bf.readLine());
		for(int i=0;i<C;i++)
		{
			hook[i]=Integer.parseInt(st.nextToken());
		}
		st=new StringTokenizer(bf.readLine());
		for(int i=0;i<G;i++)
		{
			weight[i]=Integer.parseInt(st.nextToken());
		}
		
		System.out.println(solve());
				
	}

}
